package Day016_字符流_Properties类.ZuoYe;

import java.io.FileReader;
import java.io.FileWriter;
import java.util.Properties;
import java.util.Set;

/**
 * @author zhangyan
 * @date 2020/5/8 15:55
 */
public class Test3 {
    public static void main(String[] args) throws Exception{

        //新建Properties对象
        Properties prop = new Properties();

        //调用load方法 关联流对象
        FileReader fr = new FileReader("Demo02\\aaa\\score.txt");
        prop.load(fr);

        //获取数据中的所有键
        Set<String> keySet = prop.stringPropertyNames();

        //创建字符输出流对象
        FileWriter fw = new FileWriter("Demo02\\aaa\\score.txt");

        //循环遍历所有的键
        for (String s : keySet) {
            //获取键对应的值
            String value = prop.getProperty(s);
            //判断是否有lisi键
            if (s.equals("lisi")) {
                prop.setProperty(s,"100");

            }
        }
        prop.store(fw,null);
        fw.close();
        fr.close();
    }
}
